import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('../images/circuit.tif') 
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#灰度图像 
plt.subplot(131),plt.imshow(gray, 'gray')
plt.xticks([]),plt.yticks([])

edges = cv2.Canny(gray,30,250)
plt.subplot(132),plt.imshow(edges,'gray')
plt.xticks([]),plt.yticks([])
#hough transform
lines = cv2.HoughLinesP(edges,1,np.pi/180,30,minLineLength=60,maxLineGap=10)
lines1 = lines[:,0,:]#提取为二维
for x1,y1,x2,y2 in lines1[:]: 
    cv2.line(img,(x1,y1),(x2,y2),(255,0,0),1)

plt.subplot(133),plt.imshow(img,)
plt.xticks([]),plt.yticks([])
plt.show()
